package org.enhance.common.util.encryption;

import java.util.Calendar;

public class IdCardUtil {

	private IdCardUtil() {
		throw new IllegalStateException("Constant class");
	}


	public static final String UNKOWN_SEX = "未知";

	public static int getAge(String idCard) {
		Calendar cal = Calendar.getInstance();
		String year = idCard.substring(6, 10);
		int currentYear = cal.get(Calendar.YEAR);
		return currentYear-Integer.valueOf(year);
	}

	public static String getBirth(String idCard) {
		return idCard.substring(6, 14);
	}


	public static String getSex(String idCard) {
		String sex = UNKOWN_SEX;
		String sexFlag = idCard.substring(16, 17);
		if(Integer.parseInt(sexFlag) % 2 != 0) {
			sex = "男";
		} else {
			sex = "女";
		}
		return sex;
	}

}